package com.djf.djfauth.controller;

import com.djf.djfauth.entity.LoginVO;
import com.djf.djfauth.entity.User;
import com.djf.djfauth.service.UserService;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @Author 26393
 * @Date 2025/7/7 2:29
 * @Version 1.0
 */
@RestController
@RequestMapping("/user")
public class UserController {
    @Resource
    private UserService userService;

    // 简单示例，不加密密码，不做校验
    @PostMapping("/login")
    public LoginVO login(@RequestParam String username, @RequestParam String password) {
        User user = userService.findByUsername(username);
        if (user == null || (user.getPassword() != null && !user.getPassword().equals(password))) {
            throw new RuntimeException("用户名或密码错误");
        }
        LoginVO vo = new LoginVO();
        vo.setUserId(user.getId());
        vo.setUsername(user.getUsername());
        vo.setNickname(user.getNickname());
        vo.setAvatar(user.getAvatar());
        return vo;
    }
}
